﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Common.Logging;

namespace TSharp.Core.Mvc
{
    public class TSharpDependencyResolver : IDependencyResolver
    {
        private readonly ILog log = LogManager.GetCurrentClassLogger();

        public object GetService(Type serviceType)
        {
            try
            {
                return AopContext.Services.GetThread().Get(serviceType);
            }
            catch (Exception ex)
            {
                log.WarnFormat("Type:{0}", ex, serviceType.FullName);
                return null;
            }
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return AopContext.Services.GetThread().GetAll(serviceType);
        }
    }
}